{extend name="layout" /}
{block name="body"}
 <div class="row">
      <div class="col-lg-12">
        <div class="card">
          <div class="card-body">
              <div class="form-group">
                <label for="email">发件邮箱</label>
                <input type="text" class="form-control" id="email" value="{$email.email}" placeholder="请输入发件邮箱地址">
              </div>
              <div class="form-group">
                <label for="emailpass">发件邮箱授权码</label>
                <input type="text" class="form-control" id="emailpass" value="{$email.emailpass}" placeholder="请输入邮箱授权码">
              </div>
			  <div class="form-group">
			    <label for="emailsite">SMTP地址</label>
			    <input type="text" class="form-control" id="emailsite" value="{$email.emailsite}" placeholder="请输入邮箱SMTP地址">
			  </div>
              <div class="form-group">
                <label for="emailport">SMTP端口</label>
                <input type="text" class="form-control" id="emailport" value="{$email.emailport}" placeholder="请输入邮箱发件端口">
              </div>			  
			  <div class="form-group">
			    <label for="emailname">发件人名称</label>
			    <input type="text" class="form-control" id="emailname" value="{$email.emailname}" placeholder="请输入发件人名称">
			  </div>
			  <div class="form-group">
			    <label for="test_email">测试邮箱</label>
			    <input type="text" class="form-control" id="test_email" placeholder="请输入发件人名称">
			  </div>
              <button type="button" onclick="updateemail()" class="btn btn-w-sm btn-primary mb-2">提交</button>
			  <button type="button" class="btn btn-w-sm btn-info mb-2" onclick="testemail()">测 试</button>
              <button type="button" class="btn btn-default mb-2" onclick="javascript:history.back(-1);return false;">返 回
              </button>
            </form>
          </div>
        </div>
      </div>
    </div>
{/block} {block name="js"}
<script type="text/javascript">
    function updateemail() {
        var l = $('body').lyearloading({
            opacity: 0.2,
            spinnerSize: 'lg',
            spinnerText: '后台处理中，请稍后...',
            textColorClass: 'text-info',
            spinnerColorClass: 'text-info'
        });
    	var email = $.trim($("#email").val());
    	var emailpass = $.trim($("#emailpass").val());
    	var emailport = $.trim($("#emailport").val());
    	var emailsite = $.trim($("#emailsite").val());
    	var emailname = $.trim($("#emailname").val());
		var test_email = $.trim($("#test_email").val());
        $.ajax({
            type: "POST",
            url: "{:url('app/email')}",
            data: {
                email:email,
                emailpass:emailpass,
                emailport:emailport,
                emailsite:emailsite,
                emailname:emailname
            },
            dataType: "json",
            success: function (data) {
                setTimeout(function () {
                    l.destroy();
                }, 1e3)
                if (data.code == 1) {
                    notify.success(data.msg);
                } else {
                    notify.error(data.msg);
                }
            },
            error: function () {
                l.destroy();
                notify.error("系统错误");
            }
        })
    }
	function testemail() {
	    var l = $('body').lyearloading({
	        opacity: 0.2,
	        spinnerSize: 'lg',
	        spinnerText: '后台处理中，请稍后...',
	        textColorClass: 'text-info',
	        spinnerColorClass: 'text-info'
	    });
	    var test_email = $.trim($("#test_email").val());
	    if (test_email == "" || test_email == null) {
	        l.destroy();
	        notify.error("请输入测试邮箱账号");
	        return false;
	    }
	    $.ajax({
	        type: "POST",
	        url: "{:url('app/TestEmail')}",
	        data: {
	            test_email: test_email
	        },
	        dataType: "json",
	        success: function (data) {
	            setTimeout(function () {
	                l.destroy();
	            }, 1e3)
	            if (data.code == 200) {
	                notify.success(data.msg);
	            } else {
	                notify.error(data.msg);
	            }
	        },
	        error: function () {
	            l.destroy();
	            notify.error("系统错误");
	        }
	    })
	}
</script>
{/block}